﻿package net.sealuitk.styles 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import net.sealuitk.gadgets.Grabbar;
	import net.sealuitk.Util;
	/**
	 * ...
	 * @author mkn
	 */
	dynamic public class StyleContainer
	{
		public var name:String; 
		
		public var grabbar:Grabbar;
		
		public var background:*;
		public var backgroundMode:String;
		
		public var padding:Rectangle;
		public var contentPadding:Point;
		
		// ==== FRAMES ====
		
		public var frameMode:String
		
		public var hasSides:Boolean = false;
		
		public var sideTop:BitmapData;
		public var sideBottom:BitmapData;
		public var sideLeft:BitmapData;
		public var sideRight:BitmapData;
		
		public var hasCorners:Boolean = false;
		
		public var cornerTopLeft:BitmapData;
		public var cornerTopRight:BitmapData;
		public var cornerBottomLeft:BitmapData;
		public var cornerBottomRight:BitmapData;
		
		
		public function StyleContainer(Name:String, Padding:Rectangle = null, Background:* = null) {
			name = Name; 
			if (padding != null) padding = Padding;
			else padding = new Rectangle();
			if (background != null) background = Background;
			contentPadding = new Point();
		}
		
		// ======== Set ========
		
		public function setPadding(left:Number, right:Number, top:Number, bottom:Number):void {
			padding.left = left;
			padding.right = right;
			padding.top = top;
			padding.bottom = bottom;
		}
		
		public function setContentPadding(horizontal:Number, vertical:Number):void {
			contentPadding.x = horizontal;
			contentPadding.y = vertical;
		}
		
		public function setbackground(newbackground:*, newBackgroundMode:String = null):void {
			// TODO: Flytta till Util?
			if ( Util.isBitmapSprite(newbackground) ) {
				if (background is Bitmap) background.bitmapData.dispose();
				background = newbackground;
			} else {
				if (newbackground is BitmapData) background = new Bitmap(newbackground);
				else throw Error("Background must be Bitmap, BitmapData or Sprite");
			}
			if (newBackgroundMode != null) backgroundMode = newBackgroundMode;
		}
		
		// ======== Grab Bar ========
		
		public function setGrabbar(newGrabbar:Grabbar):void {
			grabbar = newGrabbar;
		}
		
		// ======== Frames ========
		
		public function setFrameMode(FrameMode:String):void {
			frameMode = FrameMode;
		}
		
		public function setSides(left:*, right:*, top:*, bottom:*):void {
			sideLeft = Util.getBitmapData(left);
			sideRight = Util.getBitmapData(right);
			sideTop = Util.getBitmapData(top);
			sideBottom = Util.getBitmapData(bottom);
			hasSides = true;
		}
		
		public function setCorners(topLeft:*, topRight:*, bottomLeft:*, bottomRight:*):void {
			cornerTopLeft = Util.getBitmapData(topLeft);
			cornerTopRight = Util.getBitmapData(topRight);
			cornerBottomLeft = Util.getBitmapData(bottomLeft);
			cornerBottomRight = Util.getBitmapData(bottomRight);
			hasCorners = true;
		}
	}
}